#! /bin/bash
if [[ $1 == "" ]];then
   TD_DATE=`date -d '1 days ago' "+%Y-%m-%d"`
else
   TD_DATE=$1
fi
echo '========================================'
echo '==============全量导入==============='
echo '========================================'

hive   -e  "
--分区
SET hive.exec.dynamic.partition=true;
SET hive.exec.dynamic.partition.mode=nonstrict;
set hive.exec.max.dynamic.partitions.pernode=10000;
set hive.exec.max.dynamic.partitions=100000;
set hive.exec.max.created.files=150000;
--hive压缩
set hive.exec.compress.intermediate=true;
set hive.exec.compress.output=true;
--写入时压缩生效
set hive.exec.orc.compression.strategy=COMPRESSION;
--=============全量插入===============--
-- bxg_dwb.dwb_clue_wide线索主题明细表
insert into table bxg_dwb.dwb_clue_wide partition (dt)
select
        c.id as clue_id,
        c.create_date_time,
        c.update_date_time,
        c.year,
        c.year_month,
        c.month,
        c.year_month_day,
        c.day,
        c.deleted as clue_deleted,
        c.customer_id,
        c.customer_relationship_id,
        c.status,
        c.platform,
        c.s_name,
        c.area,
        c.country,
        c.province,
        c.city,
        c.name,
        c.idcard,
        c.phone,
        c.wechat,
        c.qq,
        c.email,
        c.gender,
        c.level,
        c.clue_state,
        c.is_repeat,
        r.id as relationship_id,
        r.deleted as relationship_deleted,
        r.origin_type,
        r.itcast_school_id,
        r.itcast_subject_id,
        r.creator,
        r.origin_channel,
        r.first_customer_clue_id,
        r.last_customer_clue_id,
        r.itcast_clazz_id,
        r.course_id,
        r.payment_state,
        a.id as appeal_id,
        a.customer_relationship_first_id,
        a.appeal_status,
        c.start_date as dt
from
(select * from bxg_dwd.ft_customer_relationship  where end_date='9999-99-99') r
left join bxg_dwd.ft_customer_clue c
    on c.customer_relationship_id=r.id and r.end_date='9999-99-99' 
left join bxg_dwd.dt_customer_appeal a
    on c.customer_relationship_id=a.customer_relationship_first_id  and a.end_date='9999-99-99';
insert into table bxg_dwb.dwb_relationship_wide partition (dt)
select
        r.id as relationship_id,
        r.create_date_time,
        r.update_date_time,
        r.year,
        r.year_month,
        r.month,
        r.year_month_day,
        r.day,
        r.deleted,
        r.customer_id,
        r.first_id,
        r.itcast_school_id,
        r.itcast_subject_id,
        r.creator,
        r.origin_channel,
        r.comment,
        r.first_customer_clue_id,
        r.last_customer_clue_id,
        r.itcast_clazz_id,
        r.ems_student_id,
        r.course_id,
        r.course_name,
        r.appeal_id,
        r.payment_state,
        r.total_fee,
        s.deleted as school_deleted,
        s.name as school_name,
        e.real_name,
        e.job_number,
        e.deleted as employee_deleted,
        e.scrm_department_id,
        e.tdepart_id,
        d.name as department_name,
        d.deleted as department_deleted,
        d.id_path,
        d.tdepart_code,
        sb.id as subject_id,
        sb.deleted as subject_deleted,
        sb.name,
        r.start_date as dt
from
(select * from bxg_dwd.ft_customer_relationship where end_date='9999-99-99') r
left join bxg_dwd.dt_itcast_school s on s.id=r.itcast_school_id 
left join bxg_dwd.dt_employee e on e.id = r.creator and e.end_date='9999-99-99'
left join bxg_dwd.dt_scrm_department d on e.tdepart_id = d.id and d.end_date='9999-99-99' 
left join bxg_dwd.dt_itcast_subject sb on r.itcast_subject_id = sb.id;"